import { axiosInstance } from 'src/boot/axios'
import CommonConfig from '../../assets/js/config'
import qs from 'qs'

const qsConfig = {
  arrayFormat: 'repeat',
  skipNulls: true,
  format: 'RFC3986'
}

const tpm = CommonConfig.tpmUrl + '/v1'
const schema = CommonConfig.schemaUrl + '/v1'

export function getDisLineDevice (params) {
  const url = `${tpm}/workshop/${params.workshopId}/dis_line/devices`
  const config = {
    params,
    paramsSerializer: function (params) {
      return qs.stringify(params, qsConfig)
    }
  }

  return axiosInstance.get(url, config).then(resp => {
    return Promise.resolve(resp.data)
  })
}

// 添加调度线
export function addDispatchingLine (params) {
  const url = `${schema}/dispatching_line`

  return axiosInstance.post(url, params).then(resp => {
    return Promise.resolve(resp)
  })
}

// 修改调度线
export function updateDispatchingLine (params) {
  const url = `${schema}/dispatching_line`

  return axiosInstance.put(url, params).then(resp => {
    return Promise.resolve(resp)
  })
}

// 列举调度线
export function getDispatchingLine (workshopId) {
  const url = `${schema}/dispatching_lines?workshopId=${workshopId}`

  return axiosInstance.get(url).then(resp => {
    return Promise.resolve(resp)
  })
}
// 调度线查询
export function getDispatchingLines (workshopId) {
  const url = `${schema}/workshopId/dispatching_lines?workshopId=${workshopId}`

  return axiosInstance.get(url).then(resp => {
    return Promise.resolve(resp)
  })
}

// 删除调度线
export function deleteDispatchingLine (id) {
  const url = `${schema}/dispatching_line/${id}`

  return axiosInstance.delete(url).then(resp => {
    return Promise.resolve(resp)
  })
}
